﻿@using EcBlog.Properties
@using Telerik.Web.Mvc.UI

@{
    ViewBag.Title = "Manage Users";
    Layout = "~/Areas/Admin/Views/Shared/_AdminLayout.cshtml";
}

@section head{
    @Html.Partial("_Head")
    <script type="text/javascript">
        function onError(e) {
            e.preventDefault();
            alert(e.XMLHttpRequest.getResponseHeader("message"));
        }

        function onLoadUserGrid() {
            replaceNewButtonText($(this), '@ModelLocalization.NewUser');
        }
        function onDataBoundUserGrid() {
            replaceDeleteConfirmation(this, '@ModelLocalization.DeleteConfirmation', '@ModelLocalization.User');
        }
        function onEditUserGrid(e) {
            replaceEditPopupTitle(e, '@ModelLocalization.NewUser', '@ModelLocalization.EditUser');
            hideEditPopupField(e, 'UserId');
        } 
    </script>
}

 @(Html.Telerik().Grid<EcBlog.Models.User>()
    .Name("UserGrid")
    .Columns(columns =>
        {
            columns.Command(commands =>
                {
                    commands.Edit().ButtonType(GridButtonType.Image);
                    commands.Delete().ButtonType(GridButtonType.Image);
                }).Width(80);
            columns.AutoGenerate(true);
        })
    .DataBinding(dataBinding =>
        dataBinding.Ajax()
            .Insert("Insert", "User", new { area = "Admin" })
            .Select("List", "User", new { area = "Admin" })
            .Delete("Delete", "User", new { area = "Admin" })
            .Update("Edit", "User", new { area = "Admin" }))
    .ToolBar(commands => commands.Insert().ButtonType(GridButtonType.ImageAndText))
    .DataKeys(keys => keys.Add(c => c.UserId).RouteKey("UserId"))
    .Pageable(p => p.PageSize(100))
    .Scrollable()
    .KeyboardNavigation()
    .Filterable()
    .Groupable()
    .Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
    .Reorderable(c => c.Columns(true))
    .Resizable(c => c.Columns(true))
    .Editable(c => c.Mode(GridEditMode.InLine))
    .EnableCustomBinding(true)
    .ColumnContextMenu()
    .ClientEvents(events =>
    events
        .OnError("onError")
        .OnLoad("onLoadUserGrid")
        .OnDataBound("onDataBoundUserGrid")
        .OnEdit("onEditUserGrid"))
)